package client.window;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import org.w3c.dom.ls.LSInput;

import client.Client;
import client.Emission;
import client.Reception;

public class MainFrame extends JFrame
{
	private static final long serialVersionUID = 1L;
	private Client client;
	private JMenuBar menuBar;
	private JMenu menu;
	private JMenuItem lister, modifier, ajouter, quitter;
	private JTextArea text,list;
	private JButton connexion, envoyer1, envoyer2;
	private JPanel mainPanel, addSurnamePanel, editSurnamePanel, listSurnamePanel, pConnexion;
	private JLabel lNom, lSurnom1, lSurnom2, lSurnom3, lIP;
	private JTextField tNom, tSurnom1, tSurnom2, tSurnom3, tIP ;
	
	public MainFrame()
	{
		client = new Client();
		setTitle("Client surnom");
		setSize(320,240);
		setLocationRelativeTo(null);
		setResizable(false);
		this.addWindowListener(new ListenerQuitter(this));
		
		menuBar = new JMenuBar();
			menu = new JMenu("Action");
				lister = new JMenuItem("Lister les surnoms connus");
				lister.addActionListener(new ListenerMenuList(this));
				modifier = new JMenuItem("Modifier un surnom");
				modifier.addActionListener(new ListenerMenuEdit(this));
				ajouter = new JMenuItem("Ajouter un surnom");
				ajouter.addActionListener(new ListenerMenuAdd(this));
				quitter = new JMenuItem("Quitter");
				menu.add(ajouter);
				menu.add(modifier);
				menu.add(lister);
				menu.add(quitter);
			menuBar.add(menu);
		this.add(menuBar,BorderLayout.NORTH);
		menu.setEnabled(false);
		
		lIP = new JLabel("Adresse IP");
		tIP = new JTextField();
		pConnexion = new JPanel(new GridLayout(2,1));
		pConnexion.add(lIP);
		pConnexion.add(tIP);
		
		this.add(pConnexion);
		
		connexion = new JButton("Connexion");
		connexion.addActionListener(new ListenerConnexion(this));
		this.add(connexion, BorderLayout.SOUTH);
		
		mainPanel = new JPanel(new BorderLayout());
		text = new JTextArea();
		text.setEnabled(false);
		mainPanel.add(text);
		
		lNom = new JLabel("Nom :");
		lSurnom1 = new JLabel("Surnom :");
		lSurnom3 = new JLabel("Surnom :");
		lSurnom2 = new JLabel("Surnom à remplacer:");
		
		tNom = new JTextField(30);
		tSurnom1 = new JTextField(30);
		tSurnom2 = new JTextField(30);
		tSurnom3 = new JTextField(30);
		
		envoyer1 = new JButton("Envoyer");
		envoyer1.addActionListener(new ListenerAdd(this));
		
		envoyer2 = new JButton("Envoyer");
		envoyer2.addActionListener(new ListenerModif(this));
		
		addSurnamePanel = new JPanel(new GridLayout(5,1));
		addSurnamePanel.add(lNom);
		addSurnamePanel.add(tNom);
		addSurnamePanel.add(lSurnom1);
		addSurnamePanel.add(tSurnom1);
		addSurnamePanel.add(envoyer1);
		
		editSurnamePanel = new JPanel(new GridLayout(5,1));
		editSurnamePanel.add(lSurnom2);
		editSurnamePanel.add(tSurnom2);
		editSurnamePanel.add(lSurnom3);
		editSurnamePanel.add(tSurnom3);
		editSurnamePanel.add(envoyer2);
		
		listSurnamePanel = new JPanel(new BorderLayout());
		list = new JTextArea();
		listSurnamePanel.add(list);
		
		
		this.setVisible(true);
	}
	
	public void mainBase()
	{
		removeAll();
		
		this.add(menuBar,BorderLayout.NORTH);
		this.add(connexion,BorderLayout.CENTER);
		
		validate();
		repaint();
	}

	public static void main(String[] args) 
	{
		MainFrame mf = new MainFrame();
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public JPanel getMainPanel() {
		return mainPanel;
	}

	public void setMainPanel(JPanel mainPanel) {
		this.mainPanel = mainPanel;
	}

	public JPanel getAddSurnamePanel() {
		return addSurnamePanel;
	}

	public void setAddSurnamePanel(JPanel addSurnamePanel) {
		this.addSurnamePanel = addSurnamePanel;
	}

	public JPanel getEditSurnamePanel() {
		return editSurnamePanel;
	}

	public void setEditSurnamePanel(JPanel editSurnamePanel) {
		this.editSurnamePanel = editSurnamePanel;
	}

	public JPanel getListSurnamePanel() {
		return listSurnamePanel;
	}

	public void setListSurnamePanel(JPanel listSurnamePanel) {
		this.listSurnamePanel = listSurnamePanel;
	}
	
	public JTextArea getText() {
		return text;
	}

	public JButton getConnexion() {
		return connexion;
	}

	public JTextField gettNom() {
		return tNom;
	}

	public JTextField gettSurnom1() {
		return tSurnom1;
	}

	public JTextField gettSurnom2() {
		return tSurnom2;
	}

	public JMenu getMenu() {
		return menu;
	}
	
	public JTextArea getList() {
		return list;
	}
	
	public JTextField gettSurnom3() {
		return tSurnom3;
	}

	public JLabel getlIP() {
		return lIP;
	}

	public JTextField gettIP() {
		return tIP;
	}

	public JPanel getpConnexion() {
		return pConnexion;
	}
	
	
}
